package com.Pawtrack.web.controller.info;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.Pawtrack.common.annotation.Log;
import com.Pawtrack.common.annotation.DataScope;
import com.Pawtrack.common.core.controller.BaseController;
import com.Pawtrack.common.core.domain.AjaxResult;
import com.Pawtrack.common.enums.BusinessType;
import com.Pawtrack.info.domain.PetFence;
import com.Pawtrack.info.service.IPetFenceService;
import com.Pawtrack.common.utils.poi.ExcelUtil;
import com.Pawtrack.common.core.page.TableDataInfo;
import com.Pawtrack.common.utils.SecurityUtils;

/**
 * 电子围栏Controller
 * 
 * @author ruoyi
 * @date 2025-08-14
 */
@RestController
@RequestMapping("/system/fence")
public class PetFenceController extends BaseController
{
    @Autowired
    private IPetFenceService petFenceService;

    /**
     * 查询电子围栏列表
     */
    @GetMapping("/list")
    @DataScope(deptAlias = "p", userAlias = "p")
    public TableDataInfo list(PetFence petFence)
    {
        startPage();
        List<PetFence> list = petFenceService.selectPetFenceList(petFence);
        return getDataTable(list);
    }

    /**
     * 导出电子围栏列表
     */
    @Log(title = "电子围栏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PetFence petFence)
    {
        List<PetFence> list = petFenceService.selectPetFenceList(petFence);
        ExcelUtil<PetFence> util = new ExcelUtil<PetFence>(PetFence.class);
        util.exportExcel(response, list, "电子围栏数据");
    }

    /**
     * 获取电子围栏详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(petFenceService.selectPetFenceById(id));
    }

    /**
     * 新增电子围栏
     */
    @Log(title = "电子围栏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PetFence petFence)
    {
        // 设置创建人为当前用户ID
        petFence.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        return toAjax(petFenceService.insertPetFence(petFence));
    }

    /**
     * 修改电子围栏
     */
    @Log(title = "电子围栏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PetFence petFence)
    {
        // 设置更新人为当前用户ID
        petFence.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
        return toAjax(petFenceService.updatePetFence(petFence));
    }

    /**
     * 删除电子围栏
     */
    @Log(title = "电子围栏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(petFenceService.deletePetFenceByIds(ids));
    }
}
